package com.indusfo.spc.controller;

import com.indusfo.spc.pojo.BasisList;
import com.indusfo.spc.service.BasisListService;
import com.indusfo.spc.vo.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @ProjectName: IEIS2-COM
 * @Package: com.indusfo.spc.controller
 * @ClassName: BasisListController
 * @Author: 熊冰
 * @Description: 工艺文件库 视图层
 * @Date: 2019/8/26 15:12
 * @Version: 1.0
 */
@Controller
@RequestMapping("/basisList")
public class BasisListController {
    /**
     * 注入service
     */

    @Resource
    BasisListService basisListService;
    //新增
    @RequestMapping(value="insertBasisList")
    @ResponseBody
    public JSONObject insertBasisList(BasisList basisList){
        basisList.setBasislistId(null);
        JSONObject json = basisListService.insertOrUpdateBasisList(basisList) ;
        return json;

    }
    //删除
    @RequestMapping(value="deleteBasisList")
    @ResponseBody
    public JSONObject deleteBasisList(Long[] ids){
        Integer   dataState = 2;
        JSONObject json = basisListService.deleteBasisList(ids,dataState);
        return json;

    }
    //修改
    @RequestMapping(value="updateBasisList")
    @ResponseBody
    public JSONObject updateBasisList(BasisList basisList){
        JSONObject json = basisListService.insertOrUpdateBasisList(basisList) ;
        return json;

    }
    //查询
    @RequestMapping(value="queryBasisList")
    @ResponseBody
    public JSONObject queryBasisList(BasisList basisList){
        JSONObject json = basisListService.listBasisList(basisList);
        return json;
    }
    //停用
    @RequestMapping(value="stopBasisList")
    @ResponseBody
    public JSONObject stopBasisList(Long[] ids){
        Integer   dataState = 3;
        JSONObject json = basisListService.deleteBasisList(ids,dataState);
        return json;

    }

    //启用
    @RequestMapping(value="startBasisList")
    @ResponseBody
    public JSONObject startBasisList(Long[] ids) {
        Integer dataState = 1;
        JSONObject json = basisListService.deleteBasisList(ids, dataState);
        return json;
    }
    //文件上传
    @RequestMapping(value = "/insertFile")
    @ResponseBody
    public JSONObject insertFile(MultipartFile file) throws IOException {
        JSONObject json =  basisListService.insertFile(file);
        return json;
    }
    //批量新增
    @RequestMapping(value = "/batchInsertBasisList")
    @ResponseBody
    public JSONObject batchInsertBasisList(@RequestBody List<BasisList> basisLists) {

        JSONObject json = basisListService.batchInsertBasisList(basisLists);
        return json;
    }

    //文件导入
    @RequestMapping(value = "/leadFile")
    @ResponseBody
    public JSONObject leadFile(MultipartFile file) throws IOException {
        JSONObject json =  basisListService.leadFile(file);
        return json;
    }

    //批量新增
    @RequestMapping(value = "/batchLeadFile")
    @ResponseBody
    public JSONObject batchLeadFile(MultipartFile file,Boolean way) {

        JSONObject json = basisListService.batchLeadFile(file,way);
        return json;
    }

}